
/***************************************
 * 公共 API接口地址
 ***************************************/
var $ajax={
	//登录 测试
	userLogin:function(HtUsercode,HtUserPin,success){
		$app.postAjax('/login',{
			username:HtUsercode,
			password:HtUserPin
		},function(res){
			success(res.data)
		});
	},

	//创建来访单
	accessSave:function(obj,success){
		$app.postAjax('access/save', obj, function (res) {
			$app.toast('提交成功',true,function(res){
				success(res);
			});
		})
		
	},


	accessChangeStatus(item) {
		const nowTime = new Date()
		const orderTime = new Date(item.accessTime)

		if(item.status === '0'){
			item.status = nowTime.getTime() > orderTime.getTime() ?  10 : 20
		}
		
		return item
	},
	
	/**
	 * @function 类型数据处理
	 */
	accessListFilter(list){

		const filter =  $app.pipe(

			/**
			 * @function 分离“过期”类型
			 * @summary "过期" "未访"
			 */
			list => list.map($ajax.accessChangeStatus),
			
		)

		return filter(list)

	},
	
	//获取来访列表
	accessList:function(status,pageNo,keyword, orderBy, success){
		
		$app.postAjax('access/list', {
			status,
			pageNo,
			orderBy,
			keyword,
			pageSize:$app.pageLimit,
		}, function (res) {
			success(Object.assign({}, res, { data: $ajax.accessListFilter(res.data || []) }));
		});

	},
	//获取常用联系人
	getAlways:function(page,keyword,success){
		$app.postAjax('access/getAlways', {
			pageNo:page,
			pageSize:$app.pageLimit,
			keyword:keyword
		}, function (res) {
			success(res);
		});
		
	},
	//来访详情
	accessDetail:function(id,success){
		$app.postAjax('access/detail', {
			aid:id
		}, function (res) {
			success(Object.assign({}, res, { data: $ajax.accessChangeStatus(res.data) }));
		});
	},
	//改变来访单状态
	accessDone:function(id,status,cancleReason,success){
		$app.postAjax('access/done', {
			id:id,
			status:status,//0：预约，1：已访，4：待审批，9：取消
			cancleReason:cancleReason
		}, function (res) {
			success(res);
		});
	},
	//获取来访常用语
	accessCyy:function(success){
		if($app.apiWhere){
			$app.postAjax('access/cyy', {}, function (res) {
				success(res.data);
			});
		}else{
			success([{
				content:'洽谈项目'
			},{
				content:'探望家属'
			},{
				content:'找领导喝茶'
			},{
				content:'宕机修复'
			}]);
		}
		
		
	},

	//获取来拒绝用语
	getCancleRreasonList:function(success){
		$app.postAjax('access/getCancleRreasonList', {}, function (res) {
			success(res.data);
		});
		
	},
	//再次预约
	saveAgain:function(id,time,success){
		$app.postAjax('access/saveAgain', {
			id:id,
			time:time
		}, function (res) {
			success(res);
		});
	},
	//判断是不是 重点人员:mzBack满足 okBack不满足
	juImporPer:function(idcard,mzBack,okBack){

		if($app.apiWhere){
			$app.setTimeout=2000;
			$app.postAjax({
				url:'http://68.174.0.43:8083/supp/person/getSupervision'
			}, {
				sfzh:idcard
			}, 
			function (res) {
				
				var resData=res.obj;
				if($app.judgeData(resData.person)){
					var text=resData.zdrylbbjBuffer||resData.zdryxl;
					//$app.alert(text,'重点人员');
					mzBack instanceof Function && mzBack();
				}else{
					okBack instanceof Function && okBack();
				}
			});
		}else{
			$app.loading('hide');
			okBack();
		}
		
	},

	//判断是不是 临控人员:mzBack满足 okBack不满足
	juLinKong:function(idcard,mzBack,okBack){
		if($app.apiWhere){
			$app.setTimeout=2000;
			$app.postAjax({
				url:'http://68.174.0.43:8083/supp/person/getkeyperson'
			}, {
				sfzh:idcard
			}, function (res) {
				var resData=res.obj;
				
				if($app.judgeData(resData)){
					//$app.alert(idcard+'为临控人员','临控人员');
					mzBack instanceof Function && mzBack();
				}else{
					okBack instanceof Function && okBack();
				}
			});

		}else{
			$app.loading('hide');
			okBack();
		}
		
	},
	//短信模块导入
	getByMessage:function(text,success){
		if($app.apiWhere){
			$app.postAjax('access/getByMessage', {
				message:text
			}, function (res) {
				success(res.data);
			});
		}else{
			$app.loading('hide');
			var resData=[{
				name:'周杰伦',
				idCard:'441999199202041111',
				phone:'13558766511'
			},{
				name:'张学友',
				idCard:'441888199402042222',
				phone:'13558766577'
			}];
			success(resData);
		}
		
	},

};
